package cn.com.yunhe.controller;



import cn.com.yunhe.bean.CCarColor;


import cn.com.yunhe.service.CCarColorService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @Author: 赵长松
 * @Date: 2019/1/7 15:14
 * @Version 1.0
 */
@Controller
public class CCarColorController {
    @Resource
    private CCarColorService cCarColorService;
    /*
    车辆颜色首页面
    * */
    @RequestMapping("/colorList")
    public String colorList(){
        return "houtai/carcolor";
    }
    /*
    *获取所有的颜色
    * */
    @RequestMapping("/getallcolor")
    @ResponseBody
    public List<CCarColor> getallcolor(CCarColor cCarColor){
        System.out.println(cCarColor);
        Map map = new HashMap();
        map.put("cCarColor",cCarColor);
        List<CCarColor> querycolors = cCarColorService.querycolors(map);
        return querycolors;
    }
    /*
    * 进入新增颜色的页面
    * */
    @RequestMapping("/addcolor")
    public String addColor(){
        return "houtai/addcolor";
    }
    /*
    * 处理新增
    * */
    @RequestMapping("/dealwithaddcolor")
    public String dealAddColor(CCarColor cCarColor){
        Integer integer = cCarColorService.addColor(cCarColor);

        if (integer>0){
            return "carcolor.html";
        }else{
            return "houtai/addcolor";
        }
    }

    /*
    * 进入修改页面并获得相应的信息
    * */
    @RequestMapping("/updatecolortem")
    public ModelAndView updateColorTem(String id){
        CCarColor cCarColor = cCarColorService.queryOneColor(Integer.parseInt(id));
        ModelMap modelMap = new ModelMap();
        modelMap.addAttribute("cCarColor",cCarColor);
        return new ModelAndView("houtai/updatecolor",modelMap);
    }
    /*
    *处理修改操作
    * */
    @RequestMapping("/updatecolor")
    public String updateColor(CCarColor cCarColor){
        Integer integer = cCarColorService.uptColor(cCarColor);
        if (integer>0){
            return "houtai/carcolor";
        }else{
            return "houtai/updatecolor";
        }
    }
    /*
     *处理删除操作
     * */
    @RequestMapping("/delcolor")
    @ResponseBody
    public Boolean delColor(String id){
        Boolean bool;
        Integer integer = cCarColorService.delColor(Integer.parseInt(id));
        if (integer>0){
            bool = true;
        }else {
            bool = false;
        }
        return bool;
    }
}
